package cn.imnaer.service.rpc.push.impl;

import java.util.List;

import org.bson.BSONObject;
import org.bson.BasicBSONObject;

import cn.imnaer.database.MatchConst;
import cn.imnaer.service.persistence.model.PushMessage;
import cn.imnaer.service.rpc.push.dao.MessagePushActiveRecord;

public class PushComponentRpcApiImpl {

    private final MessagePushActiveRecord messagePushActiveRecord = MessagePushActiveRecord.getInstance();

    public  List<PushMessage>  getPushMessages(String userId){
		BSONObject orderBy=new BasicBSONObject();
		orderBy.put("createTime", -1);
		BSONObject matcher=new BasicBSONObject();
		matcher.put("receiver",userId);
        List<PushMessage> record = this.messagePushActiveRecord.findAll(matcher, orderBy);
        MessagePushActiveRecord.getInstance().delete(matcher);
		return  record;
	}


	public  int  getPushMessagesCount(String userId){
		BSONObject matcher=new BasicBSONObject();
		matcher.put("receiver", userId);
        int count = this.messagePushActiveRecord.getCount(matcher);
        return  count;			
	}

}
